package com.hp.airmap.common;

import java.util.HashSet;
import java.util.Set;

import rx.Subscription;

/**
 * 创建时间： 2016/12/29
 * 作者：胡鹏
 * 用途：将RxJava被观察对象加入一个队列
 */

public class SubscriptionWrapper {
    private Set<Subscription> subscriptionList;
    public SubscriptionWrapper(){
        subscriptionList=new HashSet<>();
    }
    public void add(Subscription subscription){
        if (!subscription.isUnsubscribed()){
            subscriptionList.add(subscription);
        }
    }
    public void cancelAll(){
        for (Subscription subscription:subscriptionList){
            if (subscription!=null&&!subscription.isUnsubscribed()){
                subscription.unsubscribe();
            }
        }
        subscriptionList=new HashSet<>();
    }
}
